<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Shopping Cart</title>
    <link href="../styles/style.css" rel="stylesheet" type="text/css" /> 
    <link rel="icon" type="image/png" href="../images/dpicon.png" />    
</head>

<body>
<%@ page import="java.util.*, java.text.*,controller.*, bean.*"%>
<%
	Integer cartItemCount = session.getAttribute("cartItemCount") != null 
										? (Integer)session.getAttribute("cartItemCount") : 0;
%>

<div id="page-wrap">
	<div id="profile-menu">
		<ul class="profile-menu-list">			
			<li><a href="#" title="user">${customer.screenName}</a></li>						
			<li><a href="controller.AccountInformation" title="my account">my account</a></li>
			<li><a href="controller.Logout">logout</a></li>	
		</ul>
	</div><br/>
	
	<div id="main-menu">
		<!--<img src="devilpepperLogo.jpg" alt="devilpepper logo"/>-->
		<ul>
			<li><a href="controller.BookSearchForm" title="search">search</a></li>
			<li><a href="controller.SellBooksForm" title="sell books">sell books</a></li>
			<li><a href="controller.AboutForm" title="about">about</a></li>
			<li><a href="controller.ContactUsForm" title="contact us">contact us</a></li>
			<li class="cart"><a href="controller.CartForm" title="cart">cart&nbsp;&nbsp;<strong><%=cartItemCount%></strong></a></li>		
		</ul>		
	</div><br/>
	
	
	<div id="account">
	<%if(session.getAttribute("cart") != null) {%>				                	
       	<h1>Order Form</h1>
       	<h1>Steps: 1&nbsp;<span class="steps">2</span></h1>
		<div class="line"></div>      	
    </div>
        	
       	<div class="cartTitle">items</div>        	 
       	<table class="cartTable" border="0" cellpadding="0" cellspacing="0" >
       		<tr class="cartRowSeparator"></tr>
       		<tr>
	       		<th width="585"; style="text-align:left">BOOK NAME</th>	       		
	       		<th width="65">PRICE</th>
	       		<th width="50">QUANTITY</th>
	       		<th width="100">TOTAL</th>
       		</tr>
       		<% 	
       			Integer rowClass = 0; 
       		   	Double itemTotal = 0.0;
       		   	Double shippingCost = 4.99;
       		   	Double totalCost = 0.0;
       		 	DecimalFormat df = new DecimalFormat("##.00");
       		 	
       		 	HashMap<Integer, BookBean> cartList = (HashMap<Integer, BookBean>)session.getAttribute("cart");
       			for(BookBean book: cartList.values()) {
       				
       			itemTotal += book.getPrice();
       			df.format(itemTotal);       			
       		%>
       		<tr class="cartItemSeparator"></tr>
       		<tr id="cartItem" class="row<%=rowClass%>"><!-- this will alternate item background color -->
       			<td>
       			<div class="cartBookTitle">
       				<div><%=book.getTitle() %></div>
       				<div class="cartBookTitleAuthor">
       					<%=book.getAuthorFirstName()%>&nbsp;
       					<%=book.getAuthorLastName()%>
       				</div>
       			</div>
       			</td>       			
       			<td><%=book.getPrice() %></td>
       			<td>1</td> <!-- Since there won't be more than 1 book, the quantity will always be 1 -->
       			<td><%=book.getPrice() %></td>
       		</tr>
       		<tr class="cartRowSeparator"></tr>
       		<% rowClass = 1 - rowClass;} %>       		
       	</table>
       	 
       	
		<div class="cartTitle">totals</div>		
		<table class="cartTable" border="0" cellpadding="0" cellspacing="0">
			<tr class="cartItemSeparator"></tr>
			<tr>
				<td style="width: 600px"></td>
				<td style="width: 120px; text-align: right;">Item Total</td>
				<td style="width: 60px; text-align: center;">=</td>
				<td style="width: 70px;"><%=itemTotal%></td>
			</tr>
			<tr>
				<td style="width: 600px"></td>
				<td style="width: 120px; text-align: right;">Shipping Total</td>
				<td style="width: 60px; text-align: center;">=</td>
				<td style="width: 70px;"><%=shippingCost%></td>
			</tr>
			<tr>
				<td style="width: 600px"></td>
				<td style="width: 120px; text-align: right;">Total</td>
				<td style="width: 60px; text-align: center;">=</td>
				<td style="width: 70px;"><%=itemTotal +shippingCost %></td>
			</tr>
			<tr class="cartRowSeparator"></tr>					
		</table>
		
		<form action="controller.Checkout" method="post">
		<div class="cartButton"> 
			<button type="submit" name="continueShopping" value="continue">Continue Shopping</button>			
			<button type="submit" name="payment" value="payment">Make Payment</button>		
		</div>
		</form>	
		<%}else{ %>
			<h2>WHAT!!! No item added in shopping cart!</h2>
		<%} %>					
</div>	

<div class="footer_container">
	&copy;2011 All Rights Reserved
	<a href="mailto:devilpepper@hotmail.com">Devilpepper</a>
</div>

</body>
</html>
